package js;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.commons.dbutils.DbUtils;
import org.apache.log4j.Logger;

import com.nl.redis.RedisCluster;
import com.nl.util.ConfigUtils;
import com.nl.util.ConnectionManager;

public class App 
{
	private static final Logger logger = Logger.getLogger(App.class);
	public static int count1;
	public static String REDISIP;
	static{
		REDISIP = ConfigUtils.getInstance().getValue("redisIp");
	}

	public static void main( String[] args ) 
	{	
		System.out.println(REDISIP);
		RedisCluster cluster = null;
		try {
			cluster = new RedisCluster(REDISIP);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		StringBuffer sBuffer  = new StringBuffer();
		sBuffer.append("select id from sms_realtime_control");
		String updateSql = "update SMS_REALTIME_CONTROL t set t.total_count=?,t.year_count=?," +
				"t.quarter_count=?,t.month_count=?,t.week_count=?,t.day_count=?,t.time_count=?," +
				"t.modify_time=sysdate where t.id=?";
		Connection	conn1 = null;
		PreparedStatement pres1 = null;
		ResultSet rs = null;
		try {
			conn1 = ConnectionManager.getInstance().getConnection();
			pres1 = conn1.prepareStatement(sBuffer.toString());
			rs = pres1.executeQuery();
			PreparedStatement pres = conn1.prepareStatement(updateSql);
			while (rs.next()) {
				String mgrId = rs.getString("id");
				pres.setLong(1, Long.parseLong(cluster.get(mgrId+"totalCount")));
				pres.setLong(2, Long.parseLong(cluster.get(mgrId+"yearCount")));
				pres.setLong(3, Long.parseLong(cluster.get(mgrId+"quarterCount")));
				pres.setLong(4, Long.parseLong(cluster.get(mgrId+"monthCount")));
				pres.setLong(5, Long.parseLong(cluster.get(mgrId+"weekCount")));
				pres.setLong(6, Long.parseLong(cluster.get(mgrId+"dayCount")));
				pres.setLong(7, Long.parseLong(cluster.get(mgrId+"timeCount")));
				pres.setString(8, mgrId);
				pres.addBatch();
			}
			pres.executeBatch();
		} catch (Exception e) {
			logger.error(e.toString());
		} finally {
			DbUtils.closeQuietly(conn1, pres1, null);
			try {
				cluster.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
}
